579B - Finding Team Member - CodeForces Solution


brute force implementation sortings *1300

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n;
   cin>>n;
  // vector<vector<long long int>>vec;
    //vector<vector<long long int>> vec1(n * 2, vector<long long int>(n * 2, 0));
    vector<tuple<long long int, long long int, long long int>> triplets;

   /*for(int i=1;i<=n*2;i++)
   {
       vector<long long>temp;
       for(int j=1;j<=i-1;j++)
       {
           //long long hey;
           //cin>>hey;
           long long bye=-87;
           temp.push_back(bye);
       }

       vec.push_back(temp);

   }*/

   vector<long long>dorkar;

    for(int i=2;i<=(n*2);i++)
   {
       vector<long long>temp;
       for(int j=1;j<=i-1;j++)
       {
           long long hey;
           cin>>hey;
           //temp.push_back(hey);
           //vec1[i-1][j-1]=hey;
           //dorkar.push_back(hey);
           triplets.push_back(make_tuple(hey,i,j));
       }

       //vec.push_back(temp);

   }

   sort(dorkar.begin(),dorkar.end());
   sort(triplets.begin(), triplets.end());


   map<long long,long long>mapp;
   map<long long,long long>mapp1;
   map<long long,long long>mapp2;

   long long cc=0;

    for(int i=triplets.size()-1;i>=0;i--)
   {
       if(cc>=(n*2))
        break;
      long long int fir=get<0>(triplets[i]);
      long long int sec=get<1>(triplets[i]);
      long long int thir=get<2>(triplets[i]);

      if(mapp[sec]==0&&mapp[thir]==0)
      {


       mapp1[sec]=thir;
       mapp1[thir]=sec;

       //cout<<fir<<endl;
       mapp[sec]++;
       mapp[thir]++;

      cc+=2;
      }

      //cout<<fir<<" "<<sec<<" "<<thir<<endl;
   }

    for(int i=1;i<=n*2;i++)
   {
       cout<<mapp1[i]<<" ";
   }

   cout<<endl;

   //long long ii=0;

  /* for(int i=dorkar.size()-1;i>=0;i--)
   {
       if(ii>=n)
        break;

       mapp2[dorkar[i]]++;
       ii++;


   }

   long long cnt=0;

   //for(int i=dorkar.size()-1;i>=0;i--)
   //{

   int p=dorkar.size()-1;


       for(int j=1;j<n*2;j++)
       {
            if(cnt>=(n*2))
             break;
            int check=0;
           for(int k=0;k<j;k++)
           {
               //if(vec1[j][k]==dorkar[p]&&mapp[j]==0&&mapp[k]==0)
               if(mapp2[vec1[j][k]]!=0&&mapp[j]==0&&mapp[k]==0)
               {
                  // cout<<"TEsting"<<endl;
                  //cout<<j+1<<" "<<k+1<<endl;
                   mapp1[j+1]=k+1;
                   mapp1[k+1]=j+1;
                   mapp[j]++;
                   mapp[k]++;
                   check++;
                   cnt+=2;
                   p--;
                   break;
               }
           }

           //if(check!=0)
           // break;
       }
  // }*/


   //vec[3][2]= 5;

   //cout<<vec1[1][0]<<endl;

}


Comments

Submit
0 Comments
More Questions

807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points
1391C - Cyclic Permutations
11A - Increasing Sequence
1406A - Subset Mex
1365F - Swaps Again
50B - Choosing Symbol Pairs
1719A - Chip Game
454B - Little Pony and Sort by Shift
1152A - Neko Finds Grapes
1719B - Mathematical Circus
1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation
1719E - Fibonacci Strings
1696C - Fishingprince Plays With Array
1085A - Right-Left Cipher
1508B - Almost Sorted
1690C - Restoring the Duration of Tasks
1055A - Metro